<script>
	export default {
		globalData: {
			statusBarHeight: 0, //获取状态栏高度
			appid: 'wx15e97c5087c4eb3f'
		},
		onLaunch: function() {
			uni.getSystemInfo({
				success: res => {
					// console.log(res)
					this.globalData.statusBarHeight = res.statusBarHeight
					this.globalData.phoneType = res.platform
				}
			})
		},
		onShow: function() {
			// console.log('App Show')
			const openid = uni.getStorageSync("openid")
			const phone = uni.getStorageSync("phone")
			// console.log(openid, phone)
			if (openid != '' && phone != '') {
				this.registerUser(openid)
			}
			// this.registerUser()
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 以授权过的登陆
			registerUser(openid) {
				// console.log('为什么')
				this.http({
					url: "/Main/secondLogin",
					data: {
						open_id: openid,
						// sex
					},
					method: "POST",
					success: res => {
						if (res.code == 200) {
							uni.setStorage({
								key: "memberId",
								data: res.data
							})
							console.log(res.data)
							// loginState  2,// 1-员工 2-商户/代理商 3-员工+商户/代理商
							uni.setStorageSync('userData', res.data)
							if (res.data.loginState == 1 || res.data.loginState == 3) {
								const userInfo = uni.getStorageSync("userInfo")
								userInfo.id = res.data.user.customerId
								uni.setStorageSync('userInfo', userInfo)
								// console.log('怎么不跳？')
								uni.reLaunch({
									url: "/pages/index/index"
								})
							} else if (res.data.loginState == 2) {
								uni.reLaunch({
									url: "/pages/BillMessage/BillMessage"
								})
							} else {
								// 清理本地缓存
								uni.clearStorage();
                                // 跳转到登录页面
								uni.reLaunch({
									url: "/pages/login/login"
								})
							}
						}
					}
				})
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
